namespace Minimal.Web
{
    using System.Web.UI;

    /// <summary>
    /// Represents a base class for pages that have strongly typed query strings.
    /// </summary>
    /// <typeparam name="TQuery">The type of query the page uses.</typeparam>
    public abstract class QueryPage<TQuery>
        : Page, IQueryControl<TQuery> where TQuery : QueryString, new()
    {
        private TQuery _query;

        /// <summary>
        /// The QueryString of the page.
        /// </summary>
        public TQuery Query
        {
            get
            {
                if (this._query == null)
                {
                    this._query = QueryString.Parse<TQuery>(this.Request.QueryString, this);
                }

                return _query;
            }
            set { _query = value; }
        }

        QueryString IQueryControl.Query
        {
            get
            {
                return this.Query;
            }
        } 
    }
}
